<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
  <th:block th:include="include :: header('修改视频管理')" />
  <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
  <form class="form-horizontal m" id="form-shiping-edit" th:object="${shiping}">
    <h4 class="form-header h4">视频管理信息</h4>
    <input name="shipingId" th:field="*{shipingId}" type="hidden">
    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">标题：</label>
        <div class="col-sm-8">
          <input name="shipingTitle" th:field="*{shipingTitle}" class="form-control" type="text" required>
        </div>
      </div>
    </div>
    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">状态：</label>
        <div class="col-sm-8">
          <input name="shipingStatus" th:field="*{shipingStatus}" class="form-control" type="text">
        </div>
      </div>
    </div>
    <div class="col-xs-12">
      <div class="form-group">
        <label class="col-sm-3 control-label">视频文件：</label>
        <div class="col-sm-8">
          <input type="hidden" name="shipingFile" th:field="*{shipingFile}">
          <div class="file-loading">
            <input class="form-control file-upload" id="shipingFile" name="file" type="file">
          </div>
        </div>
      </div>
    </div>
    <h4 class="form-header h4">${subTable.functionName}信息</h4>
    <div class="row">
      <div class="col-sm-12">
        <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
        <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
        <div class="col-sm-12 select-table table-striped">
          <table id="bootstrap-table"></table>
        </div>
      </div>
    </div>
  </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
  var prefix = ctx + "system/shiping";
  $("#form-shiping-edit").validate({
    focusCleanup: true
  });

  function submitHandler() {
    if ($.validate.form()) {
      $.operate.save(prefix + "/edit", $('#form-shiping-edit').serialize());
    }
  }

  $(".file-upload").each(function (i) {
    var val = $("input[name='" + this.id + "']").val()
    $(this).fileinput({
      'uploadUrl': ctx + 'common/upload',
      initialPreviewAsData: true,
      initialPreview: [val],
      maxFileCount: 1,
      autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
      $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
      $("input[name='" + event.currentTarget.id + "']").val('')
    })
    $(this).fileinput('_initFileActions');
  });

  $(function() {
    var options = {
      data: [[${shiping.streamList}]],
      pagination: false,
      showSearch: false,
      showRefresh: false,
      showToggle: false,
      showColumns: false,
      sidePagination: "client",
      columns: [{
        checkbox: true
      },
        {
          field: 'index',
          align: 'center',
          title: "序号",
          formatter: function (value, row, index) {
            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
            return columnIndex + $.table.serialNumber(index);
          }
        },
        {
          field: 'streamId',
          align: 'center',
          title: '直播流ID',
          formatter: function(value, row, index) {
            var html = $.common.sprintf("<input class='form-control' type='text' name='streamList[%s].streamId' value='%s'>", index, value);
            return html;
          }
        },

        {
          field: 'streamStatus',
          align: 'center',
          title: '状态',
          formatter: function(value, row, index) {
            var html = $.common.sprintf("<input class='form-control' type='text' name='streamList[%s].streamStatus' value='%s'>", index, value);
            return html;
          }
        },

        {
          field: 'createBy',
          align: 'center',
          title: '创建人',
          formatter: function(value, row, index) {
            var html = $.common.sprintf("<input class='form-control' type='text' name='streamList[%s].createBy' value='%s'>", index, value);
            return html;
          }
        },

        {
          field: 'createData',
          align: 'center',
          title: '创建时间',
          formatter: function(value, row, index) {
            var html = $.common.sprintf("<input class='form-control' type='text' name='streamList[%s].createData' value='%s'>", index, value);
            return html;
          }
        },

        {
          title: '操作',
          align: 'center',
          formatter: function(value, row, index) {
            var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
            return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
          }
        }]
    };
    $.table.init(options);
  });

  function addRow() {
    var count = $("#" + table.options.id).bootstrapTable('getData').length;
    var row = {
      index: $.table.serialNumber(count),
      streamId: "",
      streamStatus: "",
      createBy: "",
      createData: "",
    }
    sub.addRow(row);
  }
</script>
</body>
</html>